const callBack = {

    openItem: function (ele) {
        ele.find('.arrow').on('click', function () {
    
            if (ele.hasClass('isOpen')) {
                ele.removeClass('isOpen')
                ele.find('.arrow').css({
                    transform: 'rotate(0deg)'
                })
                ele.css({
                    height: '2.9vh'
                })
            } else {
                ele.addClass('isOpen')
                ele.find('.arrow').css({
                    transform: 'rotate(90deg)'
                })
                ele.css({
                    height: 'auto'
                })
            }
            datas.scroll.refresh();
        })
    },


    pass: function (id) {
        datas.checkOrder.responseOfficerId = id;
    },


    runOperator(greeting) {
        datas.checkOrder.warningEventId = greeting
        $('.getAllOperationGroup .operatorItem').empty()
        datas.getAllOperationGroup().then(function (res) {
            $('.getAllOperationGroup').show()
            const data = res.data.filter(function (e) {
                return !e.disabled
            }).slice(0, 4)
            console.log(data)
            data.forEach(function (e) {
                var ele = $('.contentModal .item').clone()
                ele.find('.name').text(e.name)
                ele.attr('userid', e.value)
                ele.appendTo($('.operatorItem'))
            })
            $('.operatorItem .item').on('click', function () {
                const src = $(this).find('.icon').attr('src')
                datas.checkOrder.responseOfficerId = $(this).attr('userid')
                if(!src.match('_checked')) {
                    $(this).find('.icon').attr('src', src.replace(/(?=.png)/g, '_checked'))
                }else{
                    // $(this).find('.icon').attr('src', src.replace(/_checked/g, ''))
                }
                
                $(this).siblings().find('.icon').attr('src', './img/radio.png')
            })

        })
    },
    runMeetingList: function () {
        datas.meetingList().then(function (res) {
            let data = res.beans
            data = data.filter(function (e) {
                let result = true
                datas.meetingIds.forEach(function (v) {
                    if(v === e.applyRequestId){
                        result = false
                    }
                })
                return result
            })
            data.forEach(function (e, i) {
                var ele = $('.alertItemMode .item').clone()
                ele.show()
                ele.attr('applyRequestId', e.applyRequestId)
                // ele.attr('roomId', e.roomId)
                // ele.attr('userId', e.userId)
                ele.find('.word').text(
                    [
                        e.userName,
                        e.buildingName,
                        e.roomNumber,
                        e.meetingTheme,
                        e.startDate
                            .replace('2018-', '')
                            .split(':').slice(0, 2)
                            .join(":") + '-' + e.endDate.replace('2018-', '')
                            .split(':')
                            .slice(0, 2)
                            .join(":")].join(' ')
                )
                ele.find('button').on('click', function () {
                    datas.meetingId = $(this).parents('.item').attr('applyRequestId')
                    $('.successBig').show()
                    setTimeout(function () {
                        $('.successBig').hide()
                    }, 1.5e3)   
                    $(this).parents('.item').hide()
                    datas.meetingIds.push(datas.meetingId)
                    store.set('meetingIds',datas.meetingIds)
                })
                ele.html(ele.html().replace(/洛阳分公司/g, ''))
                ele.find('.alertButtons').hide()
                ele.appendTo($('.alertItems'))
                callBack.openItem(ele)
            })
        })
    },
    
    runAlertList: function () {
        datas.alertList().then(function (res) {
            var data = res.beans.sort(function (a, b) {
                return parseInt(a.eventProcessStatus) - parseInt(b.eventProcessStatus)
            })
            data = data.filter(function (e) {
                let result = true
                datas.warningEventIds.forEach(function (c) {
                    if(c === e.warningEventId) {
                        result = false
                    }
                })
                return result
            })
            data.forEach(function (e, i) {
                var ele = $('.alertItemMode .item').clone()
                ele.show()
                ele.attr('warningEventId', e.warningEventId)
                ele.find('.word .baseInfo').text(
                    [
                        e.buildingName,
                        e.deviceName,
                        e.applyTime.replace('2018-', '').split(':').slice(0, 2).join(":")
                    ].join(' ')
                )
                ele.find('.word .detailInfo').html(e.eventDescribe)
                ele.find('.meettingButtons').hide()
                ele.html(ele.html().replace(/洛阳分公司/g, ''))
                ele.appendTo($('.alertItems'))
                callBack.openItem(ele)
                ele.find('button').on('click', function () {
                    callBack.runOperator(ele.attr('warningEventId'))
                })
            })
            datas.scroll = new IScroll('.alertItem', {
                mouseWheel: true
            }, 1e2)
        })
        
    
    },
    
    changeClass: function () {
        datas.bedapplyAnalysis().then(function (res) {
            console.log(res, 1)
            const data = res.beans[0] || {
                allNum: 0,
                allGraNum: 0,
                allRate: 0,
                allAmNum: 0,
                allAmRate: 0,
                manAmNum: 0,
                manAmRate: 0,
                womanAmNum: 0,
                womanAmRate: 0,
                allPmNum: 0,
                allPmRate: 0,
                manPmNum: 0,
                manPmRate: 0,
                womanPmNum: 0,
                womanPmRate:0
            }
            $('.wholeDay .peopleNumber .number').text(data.allNum)
            $('.wholeDay .motherNumber .yunfu').text(data.allGraNum)
            $('.wholeDay .homePercent .rate').text(parseInt(data.allRate * 100) + '%')
            $('.noon .peopleNumber .word').text('入住人数：' + data.allAmNum)
            $('.noon .peopleNumber .circel').text(parseInt(data.allAmRate * 100) + '%')
    
            $('.noon .manNumber .word').text('男：' + data.manAmNum)
            $('.noon .manNumber .circel').text(parseInt(data.manAmRate * 100) + '%')
    
            $('.noon .womanNumber .word').text('女：' + data.womanAmNum)
            $('.noon .womanNumber .circel').text(parseInt(data.womanAmRate * 100) + '%')
    
            $('.night .peopleNumber .word').text('入住人数：' + data.allPmNum)
            $('.night .peopleNumber .circel').text(parseInt(data.allPmRate * 100) + '%')
    
            $('.night .manNumber .word').text('男：' + data.manPmNum)
            $('.night .manNumber .circel').text(parseInt(data.manPmRate * 100) + '%')
    
            $('.night .womanNumber .word').text('女：' + data.womanPmNum)
            $('.night .womanNumber .circel').text(parseInt(data.womanPmRate * 100) + '%')
        })
    },

    runBusHomeList: function () {
        datas.runBusHomeList().then(function(res) {
            const data = res.beans
            data.forEach(function (e) {
                var ele = $('.alertItemMode .item').clone()
                ele.show()
                ele.find('.word').text(e.buildingName + ' ' + e.deviceName + ' ' + e.applyTime.replace('2018-', '').split(':').slice(0, 2).join(":"))
                // ele.find('.pass').attr('passFlag', '0')
                // ele.find('.nopass').attr('passFlag', '-1')
                ele.appendTo($('.alertItems'))
                ele.on('click', function () {
                    if ($(this).hasClass('isOpen')) {
                        $(this).removeClass('isOpen')
                        $(this).css({
                            height: '2.9vh'
                        })
                    } else {
                        $(this).addClass('isOpen')
                        $(this).css({
                            height: '10vh'
                        })
                    }
                })
            })
        })
    },

    runBusRun: function () {
        datas.findDayConsumeAndRecharge().then(function (res) {
            const data = res.object
            const names = {
                consumemoney: '现金消费金额',
                subconsumemoney: '福利消费金额',
                surplussubmoney: '剩余福利',
                crecharge: '现金充值金额',
                wrecharge: '福利充值金额'
            }
            // $('.meetingRoomDaily .bottom').
            for (let i in data) {
                $('#' + i).text(names[i] + '：' + (data[i] < 0 ? -data[i] : data[i]))
            }
        })
    }
}



